const { execSync } = require("child_process");

function getToken() {
  let port = undefined;
  let token = undefined;
  let cmd = `wmic process where caption='LeagueClientUx.exe' get commandline`;
  let data = execSync(cmd).toString();

  data = data.split('"');
  for (let i = 0; i < data.length; i++) {
    if (data[i].indexOf("remoting-auth-token") > -1) {
      let cache = data[i].split("=");
      token = cache[1];
    }

    if (data[i].indexOf("--app-port") > -1) {
      let cache = data[i].split("=");
      port = cache[1];
    }
  }
  timer = null;

  return {
    token,
    port,
  };
}

module.exports = getToken;
